package com.yunhe.authority.repository.wechat;

import com.yunhe.authority.domain.authority.Menu;
import org.springframework.data.neo4j.annotation.Query;
import org.springframework.data.neo4j.repository.Neo4jRepository;
import org.springframework.data.repository.query.Param;

import java.util.List;

/**
 * @author zhengbo
 * @date 2021/10/19 14:56
 */
public interface KingKongDistrictRepository extends Neo4jRepository<Menu, Long> {

    @Query(" match(m:Menu),(s:Station) where ID(m)={menuId} and ID(s)={parkId} " +
            " create (m)-[kkd:KingKongDistrict{parkId:{parkId},usePlatform:{usePlatform},location:{location}}]->(s) ")
    void bindKingKongDistrict(@Param("menuId") Long menuId,
                              @Param("parkId") Long parkId,
                              @Param("usePlatform") String usePlatform,
                              @Param("location") Long location);

    @Query(" match(m:Menu)-[kkd:KingKongDistrict{parkId:{parkId},usePlatform:{usePlatform}}]->(s:Station)" +
            " where ID(s)={parkId} delete kkd" )
    void unbindKingKongDistrict(@Param("parkId") Long parkId,
                                @Param("usePlatform") String usePlatform);

    @Query(" match (m:Menu)-[kkd:KingKongDistrict{usePlatform:{usePlatform}}]->(s:Station) " +
            " where ID(s)={parkId} return m order by kkd.location ")
    List<Menu> findKingKongDistrictMenuByParkId(@Param("parkId") Long parkId,
                                        @Param("usePlatform") String usePlatform);

    @Query(" match (r:Role)-[:HAS_MENU]->(m:Menu)-[kkd:KingKongDistrict{usePlatform:{usePlatform}}]->(s:Station) " +
            "where ID(r)={roleId} and ID(s)={parkId} " +
            "return m order by kkd.location ")
    List<Menu> findKingKongDistrictMenuByRoleIdAndParkId(@Param("roleId") Long roleId,
                                                         @Param("parkId") Long parkId,
                                                         @Param("usePlatform") String usePlatform);

    @Query(" match (r:Role)-[:HAS_MENU]->(m:Menu)-[kkd:KingKongDistrict{parkId:{parkId},usePlatform:{usePlatform}}]->(s:Station)<-[:BELONG_TO_STATION]-(rt:RealStation)-[hp:HAS_COMPANIES]->(c:Company) " +
            " where  ID(r)={roleId} and ID(c)={companyId} and ID(s)={parkId}" +
            " return m order by kkd.location ")
    List<Menu> findKingKongDistrictMenuByRoleIdAndCompanyIdAndParkId(@Param("roleId") Long roleId,
                                                                    @Param("parkId") Long parkId,
                                                                    @Param("companyId") Long companyId,
                                                                    @Param("usePlatform") String usePlatform);

    @Query(" match (r:Role)-[:HAS_MENU]->(m:Menu)<-[:HAS_MENU{stationId:{parkId}}]-(s:Station)<-[:BELONG_TO_STATION]-(rt:RealStation)-[hp:HAS_COMPANIES]->(c:Company) " +
            " where  ID(r)={roleId} and ID(c)={companyId} and ID(s)={parkId} and m.systemMenuCategory={usePlatform}" +
            " return m order by m.topTime desc ")
    List<Menu> findDistrictMenuByRoleIdAndCompanyIdAndParkId(@Param("roleId") Long roleId,
                                                             @Param("parkId") Long parkId,
                                                             @Param("companyId") Long companyId,
                                                             @Param("usePlatform") String usePlatform);

    @Query(" match (r:Role)-[:HAS_MENU]->(m:Menu)<-[:HAS_MENU{stationId:{parkId}}]-(s:Station) " +
            "where ID(r)={roleId} and ID(s)={parkId} and m.systemMenuCategory={usePlatform} " +
            "return m order by m.topTime desc ")
    List<Menu> findAppMenuMoreByParkId(@Param("roleId") Long roleId,
                                       @Param("parkId") Long parkId,
                                       @Param("usePlatform") String usePlatform);

}
